var baseURL = ctx + "/activiti/task";
$(function() {
	load2();
});

function load2() {
	$("#todoTaskTable2").jqGrid({
		url: baseURL + '/alreadyTaskPrivate',
		datatype: "json",
		colModel: [
			{ label: '任务编号', name: 'id', index: "id", width: 45, key: true, search:false },
			{ label: '流程名称', name: 'processName', width: 75 },
			{ label: '任务节点', name: 'name', width: 100,search:false },
			{ label: '审批时间', name: 'endTime', sortable: false, width: 75,search:false },
			{ label: '发起人', name: 'processStartUser', width: 50,search:false },
			{ label: '状态', name: 'isEnd', width: 50,search:false,formatter:function(value,options, row){
				return value == true ? '已结束':'进行中'
			} },
			{ label: '跟踪', name: 'executionId', width: 50,search:false, formatter:function(value,options, row){
				return '<a href="#" onclick="showPhoto2(\''+row.processDefinitionId+'\',\''+row.executionId+'\')">跟踪</a>';
			}},
			{ label: '操作', name: 'id', index: "create_time", width: 50,search:false, formatter : function(value, options, row) {

				var f = '<a class="btn btn-primary btn-sm " href="#" title="查看"  mce_href="#" onclick="form2(\''
					+ row.processDefinitionId+'\',\''+row.id
					+ '\')"><i class="fa fa-eye"></i></a> ';
				return f;
			}}
		],
		viewrecords: true,
		height: 'auto',
		rowNum: 10,
		rowList : [10,30,50],
		rownumbers: true,
		rownumWidth: 25,
		width: document.body.clientWidth,
		multiselect: true,
		pager: "#todoTaskPager2",
		jsonReader : {
			root: "page.list",
			page: "page.currPage",
			total: "page.totalPage",
			records: "page.totalCount"
		},
		prmNames : {
			page:"page",
			rows:"limit",
			order: "order"
		},
		gridComplete:function(){
			//隐藏grid底部滚动条
			$("#todoTaskTable2").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
		}
	});
	$("#todoTaskTable2").filterToolbar({}).jqGrid('navGrid',"#todoTaskPager2",{//刷新按钮
		refresh: true,
		edit:false,del: false,search:false,add:false
	});
}
function reLoad2() {
	var page = $("#todoTaskTable2").jqGrid('getGridParam','page');
	$("#todoTaskTable2").jqGrid('setGridParam',{
		postData:{},
		page:page
	}).trigger("reloadGrid");
	$("#todoTaskTable2").setGridWidth(document.body.clientWidth);
}

function showPhoto2(processDefinitionId, executionId) {
	var url = ctx+'/activiti/task/trace/photo/'+processDefinitionId+'/'+executionId;
	layer.open({
		type : 2,
		title : '流程跟踪图',
		maxmin : true,
		shadeClose : false,
		area : [ '100%', '100%' ],
		content : url
	});
}

function form2(proId,id) {
	layer.open({
		type : 2,
		title : '发起流程',
		maxmin : true,
		shadeClose : false,
		area : [ '100%', '100%' ],
		content : baseURL + '/historyForm/'+ proId+'/'+id
	})
}
